/*处理登录用户权限的页面*/
import request from '@/helpers/request'
import { JSEncrypt } from 'jsencrypt' //RSA加密传输
import querystring from 'querystring' //序列化请求参数
import { format } from 'util';

let formatData = (data) => {
    return querystring.stringify(data)
}//序列化请求参数 封装函数

const URL = {
    //用户注册
    register: '/user/register',
    //判断用户是否登录
    ISLOGIN: 'islogin',
    //用户登录
    LOGIN: '/user/login',
    // 检查登录
    checkLogin: 'islogin',
    // 获取博客
    getBlog: '/blog/findAllBlogAndCommit',
    //获取验证码
    getCode: '/user/getCode',
    //获取githubtoken
    getToken: '/getToken',
    //通过token获取user
    getUser: '/getUser',
    //github登录接口
    githubLogin: '/user/githubLogin',
    //发送邮箱重置密码接口
    sendMailRestPass:'/user/sendMailRestPass',
    //重置密码接口
    restPassword:'/user/restPassword'
}

export default {
    sendMailRestPass({ mail, jumpHref }) {
        return request(URL.sendMailRestPass, 'GET', { mail, jumpHref }, { isToken: false })
    },
    restPassword({ sid, newPassword }) {
        return request(URL.restPassword, 'POST', formatData({ sid, newPassword  }), { isToken: false })
    },
    register({ name, password, code }) {
        return request(URL.register, 'POST', formatData({ name, password, code }), { isToken: false })
    },
    login({ name, password }) {
        return request(URL.LOGIN, 'POST', formatData({ name, password }), { isToken: false })
    },
    checkLogin() {
        return request(URL.checkLogin, 'get', formatData({ name }))
    },
    getCode(name, mail) {
        return request(URL.getCode, 'get', { name, mail }, { isToken: false })
    },
    getToken(code) {
        return request(URL.getToken, 'get', { code }, { isToken: false, configurl: 'http://47.91.156.35:3001/' })
    },
    getUser(token) {
        return request(URL.getUser, 'get', { token }, { isToken: false, configurl: 'http://47.91.156.35:3001/' })
    },
    githubLogin(name, password, headImg) {
        console.log(name, password, headImg)
        return request(URL.githubLogin, 'get', { name, password, headImg }, { isToken: false })
    }
}